<template>
	<view class="container d-flex flex-column">
		<view class="flex-fill form">
			<list-cell :hover="false">
				<view class="form-input w-100 d-flex align-items-center" style="position: relative;">
					<view class="label">工号</view>
					<view class="input flex-fill">
						<input type="text" v-model="member.username" placeholder="请输入工号">
					</view>
				</view>
			</list-cell><list-cell :hover="false">
				<view class="form-input w-100 d-flex align-items-center" style="position: relative;">
					<view class="label">姓名</view>
					<view class="input flex-fill">
						<input type="text" v-model="member.name" placeholder="请输入姓名">
					</view>
				</view>
			</list-cell>
			<list-cell :hover="false">
				<view class="form-input w-100 d-flex align-items-center" style="position: relative;">
					<view class="label">手机号码</view>
					<view class="input flex-fill">
						<input type="text" v-model="member.mobile" placeholder="请输入手机号码">
					</view>
				</view>
			</list-cell>
			
		</view>
		<view class="btn-box d-flex align-items-center just-content-center">
			<button type="primary" class="save-btn" @tap="save">立即绑定</button>
		</view>
	</view>
</template>

<script>
	
	import listCell from '@/components/list-cell/list-cell'
	import { mapState } from 'vuex';
	export default {
		components: {
			listCell
		},
		data() {
			const currentDate = this.getDate({format: true})
			return {
				member: {},
				date: currentDate
			}
		},
		computed: {
			...mapState(['openid', 'lang']),
		},
		onLoad() {
			this.member = this.$store.state.member;
		},
		methods: {
			async save() {

				let data = await this.$u.api.userBindDoctor({
					username: this.member.username,
					name: this.member.name,
					mobile: this.member.mobile,
				});
				if (data) {
					const updatedMember = {
						...this.$store.state.member,
						username: this.member.username,
					}
					this.$store.commit('SET_MEMBER', updatedMember)
					uni.showToast({
						title: '绑定成功',
						icon: 'success'
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 1500)
					
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
page {
	height: 100%;
}

.container {
	padding: 20rpx 30rpx;
}

.form {
	border-radius: 8rpx;
}

.form-input {
	.label {
		width: 160rpx;
		font-size: $font-size-base;
		color: $text-color-base;
	}
	
	.input {
	}
	
	.radio-group {
		display: flex;
		justify-content: flex-start;
		
		.radio {
			padding: 10rpx 30rpx;
			border-radius: 6rpx;
			border: 2rpx solid $text-color-assist;
			color: $text-color-assist;
			font-size: $font-size-base;
			
			&.checked {
				background-color: $color-primary;
				color: $text-color-white;
				border: 2rpx solid $color-primary;
			}
		}
	}
}

.btn-box {
	height: calc((100vh - 40rpx) / 2);
}

.save-btn {
	width: 90%;
	border-radius: 50rem !important;
	font-size: $font-size-lg;
}
</style>
